package com.jswl.ssm.controller;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/common")
public class CommonController {

	@PostMapping("/upload")
	@ResponseBody
	public String upload(MultipartFile uploadfile,HttpServletRequest request) throws IllegalStateException, IOException {
		String filename = uploadfile.getOriginalFilename();
		String realPath = request.getServletContext().getRealPath("/upload");
		System.out.println(realPath);
		uploadfile.transferTo(new File(realPath+"/"+filename));
		
		return "success";
	}
}
